package stack;

import java.util.Stack;

/**
 * @author Jonny Long
 * @date 2021/2/8 21:53
 */
public class Solution84 {
    public int largestRectangleArea(int[] heights) {
        Stack<Integer> stack = new Stack<Integer>();
        int len = heights.length;
        int[] result = new int[len];
        for (int i = 0; i < len; i++) {
            int nowHeight = heights[i];
            while (!stack.empty() && nowHeight>heights[stack.peek()]){
                int preIndex=stack.pop();
                result[preIndex]=i-preIndex;
            }
            stack.push(i);
        }
        for (int i:result) {
            System.out.print(i+"\t");
        }
        return 0;
    }
}
